package com.hawthorn.admin.repository.provider;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hawthorn.admin.constant.DicConstants;
import org.apache.ibatis.builder.annotation.ProviderMethodResolver;

import java.util.Map;

/**
 * @version v1.0.1
 * @Copyright: Copyright (c) 2023
 * @remark: app_user APP用户表
 * @author: yumiaoting
 * @Date: 2023/2/21 10:33
 */
public class AppUserSqlProvider implements ProviderMethodResolver
{
  public String findAppUser(Page<Map<String, Object>> page, String qc)
  {
    StringBuffer sql = new StringBuffer();
    sql.append(" select \n ");
    sql.append(" 	id, \n ");
    sql.append(" 	user_name 	userName, \n ");
    sql.append(" 	phone, \n ");
    sql.append(" 	imei, \n ");
    sql.append(" 	open_id 	openId, \n ");
    sql.append(" 	ios_id 	iosId, \n ");
    sql.append(" 	login_code 	loginCode, \n ");
    sql.append(" 	sys_user_id 	sysUserId, \n ");
    sql.append(" 	user_kind 	userKind, \n ");
    sql.append(" 	login_platform 	loginPlatform, \n ");
    sql.append(" 	login_mode 	loginMode, \n ");
    sql.append(" 	create_by 	createBy, \n ");
    sql.append(" 	create_time 	createTime, \n ");
    sql.append(" 	last_update_by 	lastUpdateBy, \n ");
    sql.append(" 	last_update_time 	lastUpdateTime, \n ");
    sql.append(" 	dept_id 	deptId, \n ");
    sql.append(" 	company_id 	companyId, \n ");
    sql.append(" 	oem_company_id 	oemCompanyId, \n ");
    sql.append(" 	del_flag 	delFlag, \n ");
    sql.append(" 	version, \n ");
    sql.append(" 	dept_code 	deptCode, \n ");
    sql.append(" 	biz_type 	bizType, \n ");
    sql.append(" 	`status`  \n ");
    sql.append(" from \n ");
    sql.append(" 	app_user \n ");
    sql.append(" where\n ");
    sql.append(qc);
    sql.append("and del_flag=0");


    return sql.toString();
  }

  /**
   * 导出
   *
   * @param fields
   * @param qc
   * @return
   */
  public static String exportAppUser(String fields, String qc)
  {
    StringBuffer sql = new StringBuffer();
    sql.append("select ");
    sql.append(fields);
    sql.append(" from app_user \n ");
    sql.append("where ");
    sql.append(qc);
    sql.append(" and del_flag = 0");
    return sql.toString();
  }

  public static String findStoreAppUser(String phone)
  {
    StringBuffer sql = new StringBuffer();
    sql.append("select \n");
    sql.append("  id, \n");
    sql.append("  dept_id deptId, \n");
    sql.append("  user_kind userKind \n");
    sql.append("from \n");
    sql.append("  app_user \n");
    sql.append("where \n");
    sql.append("  phone = '" + phone + "' \n");
    sql.append("  and instr(biz_type, " + DicConstants.APPYHYWLX_02 + ") > 0 \n");
    return sql.toString();
  }
}
